```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>迭代器设计模式：遍历集合的统一方式</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
            color: white;
        }
        .hero-title {
            font-family: 'Noto Serif SC', serif;
            text-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            border: 1px solid rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        .feature-icon {
            color: #6e8efb;
            font-size: 1.75rem;
        }
        .code-block {
            background-color: #282c34;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background-color: #1e2227;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            padding: 0.5rem 1rem;
            color: #abb2bf;
            font-size: 0.9rem;
        }
        .code-content {
            padding: 1.5rem;
            overflow-x: auto;
        }
        .highlight {
            background: linear-gradient(90deg, rgba(110,142,251,0.15) 0%, rgba(167,119,227,0.15) 100%);
            padding: 0.2rem 0.4rem;
            border-radius: 4px;
        }
        footer {
            background-color: #1a1a1a;
            color: #e0e0e0;
        }
        .footer-link:hover {
            color: #a777e3;
        }
        .mermaid {
            background-color: white;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0 mb-16">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="inline-block bg-white bg-opacity-20 rounded-full px-4 py-1 mb-4">
                <span class="text-sm font-medium">设计模式系列</span>
            </div>
            <h1 class="hero-title text-4xl md:text-5xl font-bold mb-6">迭代器设计模式</h1>
            <h2 class="text-xl md:text-2xl font-medium mb-8 opacity-90">遍历集合的统一方式</h2>
            <p class="text-lg md:text-xl max-w-3xl mx-auto opacity-90">
                提供一种统一的方式来遍历集合中的元素，同时隐藏集合的内部结构，使客户端代码更加简洁灵活。
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 mb-20">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="text-lg text-gray-700 leading-relaxed mb-8">
                迭代器设计模式是一种<b class="font-semibold">行为型设计模式</b>，它通过将遍历逻辑从集合中分离出来，提供了一种统一的方式来遍历集合中的元素，而不需要暴露集合内部的结构。这种分离使得客户端代码可以更加简洁、灵活地遍历各种集合类型。
            </p>
            
            <!-- Visualization -->
            <div class="mb-16">
                <h3 class="text-2xl font-bold mb-6 flex items-center">
                    <i class="fas fa-project-diagram feature-icon mr-3"></i>
                    <span>迭代器模式结构</span>
                </h3>
                <div class="mermaid">
                    classDiagram
                    class Client
                    class Collection {
                        &lt;&lt;interface&gt;&gt;
                        +iterator() Iterator
                    }
                    class Iterator {
                        &lt;&lt;interface&gt;&gt;
                        +hasNext() boolean
                        +next() Object
                    }
                    class ConcreteCollection {
                        +iterator() Iterator
                    }
                    class ConcreteIterator {
                        -collection: Collection
                        -position: int
                        +hasNext() boolean
                        +next() Object
                    }
                    
                    Client --> Collection
                    Client --> Iterator
                    Collection <|-- ConcreteCollection
                    Iterator <|-- ConcreteIterator
                    ConcreteCollection ..> ConcreteIterator : creates
                    ConcreteIterator --> ConcreteCollection : contains
                </div>
            </div>
        </section>

        <!-- Features Section -->
        <section class="mb-16">
            <h3 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-star feature-icon mr-3"></i>
                <span>核心特点</span>
            </h3>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl p-6">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-4">
                            <i class="fas fa-code-branch text-blue-500"></i>
                        </div>
                        <h4 class="text-xl font-semibold">分离遍历逻辑</h4>
                    </div>
                    <p class="text-gray-600">迭代器模式将集合的遍历逻辑从客户端代码中分离出来，提供了统一的遍历接口，简化了客户端代码。</p>
                </div>
                
                <div class="card bg-white rounded-xl p-6">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-purple-50 flex items-center justify-center mr-4">
                            <i class="fas fa-lock text-purple-500"></i>
                        </div>
                        <h4 class="text-xl font-semibold">封装内部结构</h4>
                    </div>
                    <p class="text-gray-600">隐藏了集合的内部实现细节，客户端无需关心集合的具体结构，只需通过迭代器接口访问元素。</p>
                </div>
                
                <div class="card bg-white rounded-xl p-6">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-indigo-50 flex items-center justify-center mr-4">
                            <i class="fas fa-random text-indigo-500"></i>
                        </div>
                        <h4 class="text-xl font-semibold">多种遍历方式</h4>
                    </div>
                    <p class="text-gray-600">可以定义不同的迭代器来支持多种遍历方式，如正序、倒序、过滤遍历等，而不需要修改集合本身。</p>
                </div>
                
                <div class="card bg-white rounded-xl p-6">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-pink-50 flex items-center justify-center mr-4">
                            <i class="fas fa-plug text-pink-500"></i>
                        </div>
                        <h4 class="text-xl font-semibold">标准化接口</h4>
                    </div>
                    <p class="text-gray-600">定义了标准的迭代器接口（如<code class="highlight">hasNext()</code>和<code class="highlight">next()</code>），统一了不同集合的访问方式。</p>
                </div>
            </div>
        </section>

        <!-- Use Cases -->
        <section class="mb-16">
            <h3 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-lightbulb feature-icon mr-3"></i>
                <span>适用场景</span>
            </h3>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl p-6">
                    <div class="text-blue-500 mb-4">
                        <i class="fas fa-list-ol text-3xl"></i>
                    </div>
                    <h4 class="text-lg font-semibold mb-2">遍历集合元素</h4>
                    <p class="text-gray-600">当需要遍历集合中的元素时，可以使用迭代器模式来提供一种统一的遍历方式，而不必关心集合的具体实现。</p>
                </div>
                
                <div class="bg-white rounded-xl p-6">
                    <div class="text-purple-500 mb-4">
                        <i class="fas fa-eye-slash text-3xl"></i>
                    </div>
                    <h4 class="text-lg font-semibold mb-2">隐藏集合实现</h4>
                    <p class="text-gray-600">当不希望客户端代码依赖集合的内部实现时，迭代器模式可以很好地封装内部结构，降低耦合度。</p>
                </div>
                
                <div class="bg-white rounded-xl p-6">
                    <div class="text-indigo-500 mb-4">
                        <i class="fas fa-directions text-3xl"></i>
                    </div>
                    <h4 class="text-lg font-semibold mb-2">多种遍历方式</h4>
                    <p class="text-gray-600">当需要支持多种遍历方式（如正序、倒序、按条件过滤等）时，可以定义不同的迭代器实现。</p>
                </div>
            </div>
        </section>

        <!-- Framework Applications -->
        <section class="mb-16">
            <h3 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-cubes feature-icon mr-3"></i>
                <span>框架中的应用</span>
            </h3>
            
            <div class="bg-white rounded-xl overflow-hidden">
                <div class="p-6">
                    <div class="flex items-start mb-6">
                        <div class="bg-blue-100 p-3 rounded-lg mr-4">
                            <i class="fas fa-coffee text-blue-600 text-2xl"></i>
                        </div>
                        <div>
                            <h4 class="text-xl font-semibold mb-2">Java集合框架</h4>
                            <p class="text-gray-600">
                                Java的集合类（如<code class="highlight">ArrayList</code>、<code class="highlight">HashSet</code>等）都实现了<code class="highlight">Iterable</code>接口，通过<code class="highlight">Iterator</code>接口提供了一种统一的遍历方式。例如：
                            </p>
                            <pre class="bg-gray-100 p-4 rounded mt-3 text-sm">
List&lt;String&gt; list = new ArrayList<>();
// 添加元素...
Iterator&lt;String&gt; iterator = list.iterator();
while (iterator.hasNext()) {
    String item = iterator.next();
    // 处理元素...
}</pre>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <div class="bg-purple-100 p-3 rounded-lg mr-4">
                            <i class="fas fa-leaf text-purple-600 text-2xl"></i>
                        </div>
                        <div>
                            <h4 class="text-xl font-semibold mb-2">Spring框架</h4>
                            <p class="text-gray-600">
                                Spring框架中的<code class="highlight">BeanFactory</code>和<code class="highlight">ApplicationContext</code>等容器，也使用了迭代器模式来遍历bean的定义，使得用户可以统一的方式访问容器中的bean。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Example -->
        <section class="mb-16">
            <h3 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-laptop-code feature-icon mr-3"></i>
                <span>实现示例</span>
            </h3>
            
            <div class="code-block">
                <div class="code-header">
                    <div class="flex items-center">
                        <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500"></div>
                        <span class="ml-3">IteratorPatternDemo.java</span>
                    </div>
                </div>
                <div class="code-content">
                    <pre class="text-gray-200 text-sm"><code>import java.util.ArrayList;
import java.util.List;

// 迭代器接口
interface Iterator&lt;T&gt; {
    boolean hasNext();
    T next();
}

// 集合接口
interface Collection&lt;T&gt; {
    Iterator&lt;T&gt; iterator();
}

// 具体迭代器
class ConcreteIterator&lt;T&gt; implements Iterator&lt;T&gt; {
    private List&lt;T&gt; items;
    private int position = 0;

    public ConcreteIterator(List&lt;T&gt; items) {
        this.items = items;
    }

    public boolean hasNext() {
        return position &lt; items.size();
    }

    public T next() {
        T item = items.get(position);
        position++;
        return item;
    }
}

// 具体集合
class ConcreteCollection&lt;T&gt; implements Collection&lt;T&gt; {
    private List&lt;T&gt; items = new ArrayList&lt;&gt;();

    public void addItem(T item) {
        items.add(item);
    }

    public Iterator&lt;T&gt; iterator() {
        return new ConcreteIterator&lt;&gt;(items);
    }
}

public class IteratorPatternDemo {
    public static void main(String[] args) {
        ConcreteCollection&lt;String&gt; collection = new ConcreteCollection&lt;&gt;();
        collection.addItem("Item 1");
        collection.addItem("Item 2");
        collection.addItem("Item 3");

        Iterator&lt;String&gt; iterator = collection.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-white rounded-xl p-8">
            <h3 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-check-circle feature-icon mr-3"></i>
                <span>模式总结</span>
            </h3>
            
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-4">
                    迭代器设计模式通过将遍历逻辑从集合中分离出来，提供了一种统一、标准化的方式来访问集合元素，同时隐藏了集合的内部实现细节。这种分离带来了以下优势：
                </p>
                <ul class="list-disc pl-6 space-y-2 mb-6">
                    <li><span class="font-medium">简化客户端代码：</span> 客户端不需要了解集合的内部结构，只需使用标准的迭代器接口</li>
                    <li><span class="font-medium">支持多种遍历方式：</span> 可以定义不同的迭代器实现来支持正序、倒序、过滤等遍历方式</li>
                    <li><span class="font-medium">降低耦合度：</span> 集合和客户端之间通过迭代器接口交互，减少了直接依赖</li>
                    <li><span class="font-medium">可扩展性强：</span> 可以轻松添加新的集合类型和对应的迭代器实现</li>
                </ul>
                <p class="text-lg text-gray-700">
                    在Java等现代编程语言的集合框架中，迭代器模式被广泛应用，成为了处理集合遍历的标准方式。掌握这一模式有助于编写更加灵活、可维护的代码。
                </p>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="py-10">
        <div class="container mx-auto max-w-5xl px-4 text-center">
            <div class="mb-4">
                <h3 class="text-xl font-medium text-white">技术小馆</h3>
            </div>
            <div>
                <a href="http://www.yuque.com/jtostring" class="footer-link text-gray-300 hover:text-white transition-colors">
                    <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```